package util

import (
	"net/http"

	"github.com/thinkeridea/go-extend/exnet"
)

// GetIP GetIP, for more: https://www.cnblogs.com/thinkeridea/p/10612602.html
func GetIP(r *http.Request) string {
	ip := exnet.ClientPublicIP(r)
	if ip == "" {
		ip = exnet.ClientIP(r)
	}

	return ip
}

// IP_Info IP_Info
// func IP_Info(ip string) string {
// 	client := http.Client{Timeout: 5 * time.Second}
// 	resp, err := client.Get(`http://ip.taobao.com/service/getIpInfo.php?ip=` + ip)
// 	if err != nil {
// 		panic(err)
// 	}
// 	defer resp.Body.Close()
// 	var buffer [512]byte
// 	result := bytes.NewBuffer(nil)
// 	for {
// 		n, err := resp.Body.Read(buffer[0:])
// 		result.Write(buffer[0:n])
// 		if err != nil && err == io.EOF {
// 			break
// 		} else if err != nil {
// 			panic(err)
// 		}
// 	}
// 	return result.String()
// }
